<template>
  <div>
    <Row :gutter="15" class="marginT10">
      <Col span="24">
        <div 
          class="pullLeft marginR20 "
          :class="($app.judgeData(companyAll) && companyAll.state==2)?' pointer':' '"
          @click="touXDo"
        >
          <Avatar 
            :src="$store.state.F_cat.userImg" 
            shape="square"
            class="tX " 
          />
        </div>
         
        <div class="overflowH">
          <Row>
            <Col span="24" style="margin-bottom:10px; margin-top:5px;">
              <template v-if="$app.judgeData(companyAll)&&companyAll.state==2">
                <span class="marginR30 f_18 f_bold c333">{{companyAll.company_name}}</span>
                <i class="iconfont iconv f_18 marginR5" style="color:#ffd712;" ></i>
                <span class="f_16 marginR30 ">已认证</span>
                <template v-if="(companyAll.level>0)">
                  <span class="f_16 cBlue marginR5">
                    <i class="iconfont iconyaoqing  marginR5 f_18"></i>
                    邀请码：
                    <span class="f_16 cBlue marginR10">{{companyAll.invite_code}}</span>
                    <Button
                      type="primary"
                      size="small"
                      class="relative"
                      style="top:-2px;"
                      @click="wtW"
                    >邀请好友</Button>
                  </span>
                </template>
                <template v-else>
                  <span class="f_16 cBlue marginR5">
                    <Icon type="ios-call" class="relative " style="top:-1px" />
                    {{userPower.mobile||userPower.name}}
                  </span>
                </template>
              </template>
              <template v-else>
                <span class=" f_18 f_bold c333">
                  <span class="cCCC marginR5">Hi,</span>
                  <span class="marginR30">{{userPower.mobile||userPower.name}}</span>
                </span>
              </template>
              <!-- 从0开始走 -->
              <template v-if="!$app.judgeData(companyAll)">
                <Button
                  type="primary"
                  size="small"
                  class="relative"
                  style="top:-2px;"
                  @click="qYZ"
                >
                  <Icon type="md-book" class="marginR5 relative"  size="16" />未认证
                </Button>
              </template>

              <!-- 已经走过1次 -->
              <template v-if="$app.judgeData(companyAll)">
                <Button
                  type="primary"
                  size="small"
                  class="relative"
                  style="top:-2px;"
                  v-show="companyAll.state==0"
                  @click="qYZ"
                >
                  <Icon type="md-book" class="marginR5 relative"  size="16" />未认证
                </Button>
                <Button
                  type="primary"
                  size="small"
                  class="relative"
                  style="top:-2px;"
                  v-show="companyAll.state==3"
                  @click="qYZ"
                >
                  <Icon type="md-book" class="marginR5 relative"  size="16" />再认证
                </Button>
                <Button
                  type="primary"
                  size="small"
                  disabled
                  class="relative"
                  style="top:-2px;"
                  v-show="companyAll.state==1"
                >
                  <Icon type="md-book" class="marginR5 relative"  size="16" />认证中
                </Button>
              </template>
            </Col>

            <Col span="24">
              <template v-if="$app.judgeData(companyAll) && companyAll.state==2">
                <div class="xwBle">
                  <span class="">公司邮箱：{{companyAll.email}}</span>
                  <!-- <span class="cCCC">暂不支持修改</span> -->
                  <Divider type="vertical" class="fenXw"/>
                </div>
                <div class="xwBle">
                  <span class="marginR10">
                    绑定银行卡：
                    <span v-show="companyAll.is_bind_blank">
                      <span>{{$app.superSlice(companyAll.blank_name,0,4)+'******'}}</span>
                    </span>
                    <span class="cCCC" v-show="!companyAll.is_bind_blank">暂未绑定</span>
                  </span>
                  <span class="cBlue textLine" @click="xG_bankCard">{{companyAll.is_bind_blank?'修改':'绑定'}}</span>
                  <Divider type="vertical" class="fenXw"/>
                </div>

                <div class="xwBle marginR20">
                  <span class="marginR10">
                    开票信息：
                    <span v-show="companyAll.invoice_number">
                      <span>{{$app.superSlice(companyAll.invoice_number,0,4)+'******'}}</span>
                    </span>
                    <span class="cCCC" v-show="!companyAll.invoice_number">暂未填写</span>
                  </span>
                  <span class="cBlue textLine marginR20" @click="xV_InvoiceSet">{{companyAll.invoice_number?'修改':'填写'}}</span>
                  <span class="marginR20 cBlue textLine  "  v-show="companyAll.invoice_number" @click="ootwC">
                    申请开票
                  </span>
                </div>

                <div class="xwBle" v-show="companyAll.level>0">
                  <span class="marginR10">
                    我的团队
                  </span>
                  <span class="cBlue textLine" @click="$router.push({name:'team'})">查看</span>
                </div>
              </template>
              <template v-else>
                <div class="cCCC ">请您，先完成企业实名认证</div>
              </template>
            </Col>

          </Row>
          
        </div>
      </Col>
    </Row>

    <!-- 账户余额 -->
    <div class="ui-bnoW">
      <div class="f_16 c333 relative" style="border-bottom:1px solid #ddd;padding-bottom:10px;">
        <i class="iconfont iconshenqingrenguanli cBlue f_24 relative marginR10" style="top:3px;"></i>
        账户余额
        <!-- <span class="pullRight c999 f_14 textLink" style="padding-top:17px;" @click="$app.alert('这里是什么内容？')">常见问题</span> -->
      </div>
      <div class="padding15-0" style="border-bottom:1px solid #ddd;">
        <ul class="seeBit">
          <li
            class="pointer"
            @click="goEw('moneyList')">
            <div>
              <span class="f_18 marginR5">总余额</span>
              <i class="iconfont iconwenhao f_14 cCCC" ></i>
            </div>
            <div class="f_bold c333 f_30">{{$app.judgeData(companyAll)?parseFloat(companyAll.balance):0}}</div>
          </li>
          <li
            class="pointer"
            @click="goEw('moneyRemainCat')">
            <div>
              <span class="f_18 marginR5">猫币</span>
              <i class="iconfont iconwenhao f_14 cCCC"  ></i>
            </div>
            <div class="f_bold c333 f_30">{{$app.judgeData(companyAll)?parseFloat(companyAll.currency):0}}</div>
          </li>
        </ul>
      </div>
      <div class="padding15-0">
        <Button type="primary" style="padding-left:30px;padding-right:30px;" @click="moneyRemainT">充值</Button>
      </div>
    </div>

    <template v-if="$app.judgeData(companyAll)&&companyAll.level>0">
      <!-- 合伙人收益 -->
      <div class="ui-bnoW">
        <div class="f_16 c333 relative" style="border-bottom:1px solid #ddd;padding-bottom:10px;">
          <i class="iconfont iconshouyigao cBlue f_24 relative marginR10" style="top:3px;"></i>
          收益
          <!-- <span class="pullRight c999 f_14 textLink" style="padding-top:17px;" @click="$app.alert('这里是什么内容？')">常见问题</span> -->
        </div>
        <div class="padding15-0" style="border-bottom:1px solid #ddd;">
          <Row>
            <Col :span="8">
              <div>
                <span class="f_18 marginR5">当日收益</span>
                <div class="f_bold c333 f_30">{{parseFloat(companyAll.today_profit)}}</div>
              </div>
            </Col>
            <Col :span="8">
              <div>
                <span class="f_18 marginR5">本月收益</span>
                <div class="f_bold c333 f_30">{{parseFloat(companyAll.month_profit)}}</div>
              </div>
            </Col>
            <Col :span="8">
              <div>
                <div
                  class="pointer"
                  @click="goEw('earnings')" 
                >
                  <span class="f_18 marginR5">累计收益</span>
                  <i class="iconfont iconwenhao f_14 cCCC" ></i>
                  <div class="f_bold c333 f_30">{{parseFloat(companyAll.history_profit)}}</div>
                </div>
                
              </div>
            </Col>
          </Row>
        </div>
        <div class="padding15-0">
          <Button 
          type="primary" 
          class="marginR10" 
          style="padding-left:30px;padding-right:30px;"
           @click="showEarningsBox" 
           :disabled="!($app.judgeData(companyAll)&&companyAll.partner_profit>=100)"
           >提现</Button>
           <i class="iconfont iconwenhao f_18 cCCC lineH1 pointer" @click="$app.alert('提现金额必须大于100元，3个工作日内到账。')" ></i>
           
          <div class="inlineBlock pullRight f_16">可提现：
            <span class="f_bold f_30 cRed lineH1">{{parseFloat(companyAll.partner_profit)}}</span>
          </div>
        </div>
      </div>
    </template>
    

    <RechargeBox ref="rechargeBox" :companyAll="companyAll" :userPower="userPower"/>
    
    <EarningsBox ref="earningsBox" />
    <CompanyGo ref="CompanyGo" />
    <HeadImgBox ref="HeadImgBox" />

    <BankCardSet ref="bankCardSet" />
    <InvoiceSet ref="InvoiceSet" />
  </div>
</template>

<style lang="less" scoped>
  @import './css/userSmall.less';
</style>

<script>

import RechargeBox from "./rechargeBox";
import EarningsBox from "./earningsBox";
import HeadImgBox from "./headImgBox";
import CompanyGo from "./companyGo";

import BankCardSet from "./bankCardSet";
import InvoiceSet from "./invoiceSet";


export default {
  name: "userSmall",
  components: { EarningsBox, RechargeBox, CompanyGo,HeadImgBox,BankCardSet,InvoiceSet},
  data() {
    let data = {};

    let tool = {};
    return Object.assign(data, tool);
  },
  created(){},
  mounted() {},
  props: ['userPower', 'companyAll'],
  watch:{
    userPower(newVal,oldVal){
      this.userPower=newVal;
    },
    companyAll(newVal,oldVal){
      this.companyAll=newVal;
    },
  },
  methods: {
    // 判断能否开票
    ootwC(){
      if(this.companyAll.invoice_number){
        this.$router.push({name:'invoiceTo'});
      }else{
        $app.alert('请先填写开票信息','温馨提示',()=>{
          this.xV_InvoiceSet();
        })
      }
    },
    xG_bankCard() {
      this.$refs["bankCardSet"].showBox = true; //显示弹框
    },
    xV_InvoiceSet(){
      this.$refs["InvoiceSet"].showBox = true; //显示弹框
    },
    //收益明细：
    goEw(name){
      this.$router.push({name});
    },
    wtW() {
      let { companyAll } = this;
      let url = window.location.href;
      let xuT = url.indexOf("/#/");
      let urlP = $app.superSlice(url,0,xuT);
      let urlA = urlP + "/#/login?invite_code=" + companyAll.invite_code;

      this.$copyText(urlA).then(
        res => {
          $app.toast("分享好友，拷贝成功", true);
        },
        err => {
          $app.toast("地址栏拷贝失败", false);
        }
      );
    },

    //自定义方法
    moneyRemainT() {
      this.$refs['rechargeBox'].rechargeBox=true;//显示弹框
    },
    //自定义方法2
    showEarningsBox() {
      let {
        companyAll:{
          is_bind_blank,
          partner_profit
        }
      }=this;
      if(!!is_bind_blank){//有绑定银行卡
        if(parseFloat(partner_profit)<100){
          $app.alert('提现金额必须大于<span class="cRed f_18 f_bold"> 100 </span>元。');
        }else{
          this.$refs["earningsBox"].showBox = true;
          this.$refs["earningsBox"].partner_profit = this.companyAll.partner_profit;
          this.$refs["earningsBox"].money = "";
        }
        
      }else{
        $app.toast('您暂未绑定银行卡',false,()=>{
          this.xG_bankCard();
        });
        
      }

      
    },
    //企业认证弹框
    qYZ() {
      this.$refs["CompanyGo"].showBox = true; //显示弹框
    },
    touXDo(){
      let {
        companyAll:{
          state
        }
      }=this;
      
      if(state==2){
        this.$refs["HeadImgBox"].showBox=true;
      }else{
        $app.toast('头像功能，需通过企业认证')
      }
    }
  }
};
</script>